home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / lan / apinst.zip / MAIN.C < prev    next >
C/C++ Source or Header  |  1994-03-17  |  9KB  |  259 lines

  1. /*
  2. ***************************************************************** 
  3.                     DISCLAIMER  
  4.   
  5. Novell, Inc. makes no representations or warranties with respect to
  6. any NetWare software, and specifically disclaims any express or
  7. implied warranties of merchantability, title, or fitness for a
  8. particular purpose.  
  9.  
  10. Distribution of any NetWare software is forbidden without the
  11. express written consent of Novell, Inc.  Further, Novell reserves
  12. the right to discontinue distribution of any NetWare software.
  13.  
  14. Novell is not responsible for lost profits or revenue, loss of use
  15. of the software, loss of data, costs of re-creating lost data, the
  16. cost of any substitute equipment or program, or claims by any party
  17. other than you.  Novell strongly recommends a backup be made before
  18. any software is installed.   Technical support for this software
  19. may be provided at the discretion of Novell.
  20. *****************************************************************
  21. */
  22. #include "main.z"
  23.  
  24.  
  25. /* *** Internal Prototypes **************************/
  26. N_INTERN_FUNC( nid )
  27. Init( void );
  28.  
  29. N_INTERN_FUNC( void )
  30. Term( void );
  31.  
  32. N_INTERN_FUNC( void )    
  33. InitNAWF( void );
  34.  
  35. N_INTERN_FUNC( void )
  36. TermNAWF( void );
  37.  
  38. N_GLOBAL_FUNC( nbool8 )
  39. OnAppAfterCREATE ( pUMsgStruct pMsg );
  40.  
  41. N_GLOBAL_FUNC( nbool8 )
  42. OnAppAfterACTION( pUMsgStruct pMsg );
  43.  
  44. /******************************************************/
  45. /*                    VECTORS                         */
  46. /******************************************************/
  47.  
  48. UInstVectorBegin( AppVector, N_NULL )
  49. UInstVectorMsg( UMSG_CREATE, UMSG_MODE_AFTER, OnAppAfterCREATE)
  50. UInstVectorMsg( UMSG_ACTION, UMSG_MODE_AFTER, OnAppAfterACTION)
  51. UInstVectorEnd( AppVector )
  52.  
  53. /***** Globals *************************************/
  54. N_GLOBAL_VAR UModAccess        Access;     /* Global access record */
  55. N_GLOBAL_VAR nid                  idResFile;  /* nid for the resource file */
  56. N_GLOBAL_VAR nid                  idApp;      /* nid of the application instance */
  57.  
  58. /****************************************************************************
  59. Function: UModMain
  60.     Application entry point.  NAWF main calls UModMain
  61. ****************************************************************************/
  62. N_GLOBAL_LIBRARY (nint32) 
  63. UModMain(nid idModule, nid idPrevInst, nflag32 flOptions)
  64. {
  65.     UMsgStruct        msg;
  66.  
  67.     idApp = Init();
  68.    if (idApp = N_NULL)
  69.    {
  70.       Term();
  71.       return (1);
  72.    }
  73.  
  74.     /* Message Get - Dispatch model */
  75.     while (UMsgGet( &Access, &msg, N_NULL, UMSG_CAT_ALL ))
  76.     {
  77.         if (UMsgMap( &Access, N_NULL, &msg, N_NULL ))
  78.         {
  79.             /* dispatch message that was not handled by UMsgMap */
  80.             UMsgDispatch( &Access, &msg, 0 );
  81.         }
  82.     }
  83.  
  84.   Term();
  85.   return (0);
  86. }
  87.  
  88. /****************************************************************************
  89. Function: Init
  90.     Initialize application components and globals.
  91. ****************************************************************************/
  92. N_INTERN_FUNC( nid )    
  93. Init( void )
  94. {
  95.     nint16            FontWidth, i;
  96.     nid                idResPack, appID;
  97.  
  98.     
  99.     /* Initialize NAWF components */
  100.     InitNAWF();
  101.  
  102.     /* Open resource file */
  103.     idResFile = UResOpenModule( &Access, UModGetModule( &Access ), URES_OPEN_READ ); 
  104.  
  105.     /* Initialize Application instance */
  106.    idResPack =UResCreatePack (&Access, idResFile, URES_TYPE_INSTANCE,
  107.                                  APP_ID, URES_PACK_NO_KEEP);
  108.    DEBUG_ASSERT (((UErrGetVal (&Access)==N_SUCCESS) &&
  109.                   (UResValidatePack (&Access, idResPack)==N_TRUE)),
  110.                           "Can't create App resource packet"); 
  111.  
  112.    /* Load application instance */
  113.    appID = UInstLoad (&Access, N_NULL, idResPack, N_NULL, N_NULL);
  114.  
  115.   return (appID);
  116. }
  117.  
  118. /****************************************************************************
  119. Function: Term
  120.     Terminate application components and globals.
  121. ****************************************************************************/
  122. N_INTERN_FUNC( void )    
  123. Term( void )
  124. {
  125.       /* Close resource file */
  126.       UResClose( &Access, idResFile, N_NULL );
  127.   
  128.       /* Terminate NAWF components */
  129.     TermNAWF();
  130. }
  131.  
  132. /****************************************************************************
  133. Function: InitNAWF
  134.     Initialize NAWF components.
  135. ****************************************************************************/
  136. N_INTERN_FUNC( void )    
  137. InitNAWF( void )
  138. {    
  139.       /* Essential foundation components */
  140.       if (! UModInit    ( &Access, UMOD_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  141.       if (! UMemInit    ( &Access, UMEM_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  142.       if (! UErrInit    ( &Access, UERR_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  143.   
  144.       /* More foundation components */
  145.       if (! UDInit    ( &Access, UD_VERSION,        0L )) UModExit( UErrGetVal( &Access ) );    
  146.       if (! UFileInit    ( &Access, UFILE_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  147.       if (! UResInit    ( &Access, URES_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  148.       if (! UFontInit    ( &Access, UFONT_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  149.       if (! UGrafInit    ( &Access, UGRAF_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  150.       if (! UMsgInit    ( &Access, UMSG_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  151.       if (! UInstInit    ( &Access, UINST_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  152.       if (! UPrefInit    ( &Access, UPREF_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  153.       if (! UPrInit    ( &Access, UPR_VERSION,        0L )) UModExit( UErrGetVal( &Access ) );
  154.       if (! USysInit    ( &Access, USYS_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  155.   
  156.       /* interface components */
  157.       if (! UItemInit    ( &Access, UITEM_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  158.       if (! UKeyInit    ( &Access, UKEY_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  159.       if (! UClipInit    ( &Access, UCLIP_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  160.     
  161.       if (! UAppInit    ( &Access, UAPP_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  162.       if (! UWndInit    ( &Access, UWND_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  163.       if (! UBtnInit    ( &Access, UBTN_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  164.       if (! UDspInit    ( &Access, UDSP_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  165.       if (! UMenuInit    ( &Access, UMENU_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  166.       if (! UEtxtInit    ( &Access, UETXT_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  167.       if (! UListInit    ( &Access, ULIST_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  168.   
  169.       if (! UVoidInit    ( &Access, UVOID_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  170.       if (! UBoxInit    ( &Access, UBOX_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  171.       if (! USldrInit    ( &Access, USLDR_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  172.       
  173.       if (! UDlgInit    ( &Access, UDLG_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  174.       
  175.       /* Standard packages */
  176.       if (! UStdFSelInit    ( &Access, USTD_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  177.       if (! UStdCSelInit    ( &Access, USTD_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  178.       if (! UPntrInit ( &Access, UPNTR_VERSION,    0L )) UModExit( UErrGetVal( &Access ) );
  179.   
  180. }
  181.  
  182. /****************************************************************************
  183. Function: TermNAWF
  184.     Terminate NAWF components.
  185. ****************************************************************************/
  186. N_INTERN_FUNC( void )    
  187. TermNAWF( void )
  188. {
  189.     UPntrTerm (&Access);
  190.       UStdCSelTerm( &Access );
  191.       UStdFSelTerm( &Access );
  192.  
  193.       UDlgTerm    ( &Access );
  194.  
  195.       USldrTerm    ( &Access );
  196.       UBoxTerm    ( &Access );
  197.       UVoidTerm    ( &Access );
  198.   
  199.       UListTerm    ( &Access );
  200.       UEtxtTerm    ( &Access );
  201.       UMenuTerm    ( &Access );
  202.       UDspTerm    ( &Access );
  203.       UBtnTerm    ( &Access );
  204.       UWndTerm    ( &Access );
  205.       UAppTerm    ( &Access );
  206.     
  207.       UClipTerm    ( &Access );
  208.       UKeyTerm    ( &Access );
  209.       UItemTerm    ( &Access );
  210.       
  211.       USysTerm    ( &Access );
  212.       UPrTerm        ( &Access );
  213.       UPrefTerm    ( &Access );
  214.       UInstTerm    ( &Access );
  215.       UMsgTerm    ( &Access );
  216.       UGrafTerm    ( &Access );
  217.       UFontTerm    ( &Access );
  218.       UResTerm    ( &Access );
  219.       UFileTerm    ( &Access );
  220.       UDTerm        ( &Access );
  221.   
  222.       UErrTerm    ( &Access );
  223.       UMemTerm    ( &Access );
  224.     UModTerm    ( &Access );
  225. }
  226.  
  227. /*****************************************************************************
  228.    OnAppAfterCREATE filter procedure is called after the UMSG_CREATE message
  229.    is post-filtered.
  230. *****************************************************************************/
  231. N_GLOBAL_FUNC( nbool8 )
  232. OnAppAfterCREATE ( pUMsgStruct pMsg )
  233. {
  234.    return N_TRUE;
  235. }
  236. /*****************************************************************************
  237.    OnAppAfterACTION filter procedure is called after the UMSG_ACTION message
  238.    is post-filtered.
  239. *****************************************************************************/
  240. N_GLOBAL_FUNC( nbool8 )
  241. OnAppAfterACTION( pUMsgStruct pMsg )
  242. {
  243.     nid idInst;
  244.    /* Store the nid of the the Application instance */
  245.     idInst = UMsgGetInst( pMsg ); 
  246.     switch( (nint16)UMsgGetParam1( pMsg ) )    /* Action code of item selected */
  247.     {
  248.         case APP_MENU_CLOSE:            /* Quit/Exit selected */
  249.         {
  250.             /* Destroy the window, but defer to messages already in queue */
  251.             UInstDestroy( &Access, idInst, UINST_DEFERRED );
  252.             break;
  253.         }
  254.    }
  255.     return N_TRUE;
  256. }
  257. /*****************************************************************************/
  258.  
  259.